import string

class Tweet:
    def __init__(self, line):
        valid_url_chars = string.ascii_letters + string.digits + './'
        line0 = line.replace(' ', '\t')
        per_line_list = line0.split('\t')
        # userid
        self.userid = int(per_line_list[0])
        # latitude and longitude
        self.latitude = float(per_line_list[2])
        self.longitude = float(per_line_list[3])
        start_index = line.find("http://4sq.com/")
        end_index = start_index + 16
        while line[end_index] in valid_url_chars:
            end_index = end_index + 1
        # url
        self.url = line[start_index:end_index]
        # keywords
        self.keywords = []
        not_keywords_list = ["the", '&', 'of', 'a']
        if "I'm at" in line:
            start_index = line.find("I'm at") + 7
            end_index = start_index + 1
            while line[end_index] not in "(.":
                end_index = end_index + 1
            current_keywords_list = line[start_index:end_index].lower().split()
            for item in current_keywords_list:
                if item in not_keywords_list:
                    continue
                elif len(self.keywords) < 2:
                    self.keywords.append(item)
                elif len(self.keywords) == 2:
                    break
        elif '(@' in line:
            start_index = line.find("(@") + 3
            end_index = start_index + 1
            while line[end_index] not in "()/":
                end_index = end_index + 1
            if line[end_index - 1] == 'w':
                end_index = end_index - 1
            current_keywords_list = line[start_index:end_index].lower().split()
            for item in current_keywords_list:
                if item in not_keywords_list:
                    continue
                elif len(self.keywords) < 2:
                    self.keywords.append(item)
                elif len(self.keywords) == 2:
                    break
        elif "the mayor of" in line and "@foursquare" in line:
            start_index = line.find("the mayor of") + 13
            end_index = line.find("@foursquare")
            current_keywords_list = line[start_index:end_index].lower().split()
            for item in current_keywords_list:
                if item in not_keywords_list:
                    continue
                elif len(self.keywords) < 2:
                    self.keywords.append(item)
                elif len(self.keywords) == 2:
                    break
                    
    
    def get_latitude(self):
        return self.latitude

    def get_longitude(self):
        return self.longitude
        
    def get_url(self):
        return self.url
        
    def get_keywords(self):
        return self.keywords   
        
    def get_userid(self):
        return self.userid
        
       
class Text:
    def __init__(self, source0, content0):
        self.source = source0    
        self.content = content0
    
    def get_type(self):
        return self.source

    def get_content(self):
        return self.content
        
